<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./lib/vue.min.js"></script>
    <script src="./lib/vue-router.js"></script>
</head>
<body>
    <div id="app">
        <!-- 如果在路由中，使用查询字符串给路由传递参数，，不需要修改路由匹配规则中的 path 属性 -->
        <router-link to = '/login/12/lisi'>登录</router-link>
        <router-link to = "/register">注册</router-link>

        <!-- 路由占位符 -->
        <router-view></router-view> 
    </div>
    
    <script>
        var login = {
            template: '<h1>登录 ----参数:{{ $route.params.id }}---姓名:{{ $route.params.name }}</h1>',
            data() {
                return {
                    msg: '123'
                }
            },
            created() { //组件的生命周期钩子函数
                console.log(this.$route)
                console.log(this.$route.params.id)
                console.log(this.$route.params.name)
            }
        }

        var register = {
            template: '<h1>注册</h1>'
        }
        
        const router = new VueRouter({
            routes: [ //匹配路由规则
                { path: '/', redirect: '/login'},
                { path: '/login/:id/:name', component: login },
                { path: '/register', component: register }
            ]
        })

        var vm = new Vue({
            el:"#app",
            data:{},
            methods: {},
            //router: router 可简写
            router
        })
    </script>
</body>
</html>